// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()

exports.main = async (event, context) => {
  const { type, page = 1, pageSize = 10 } = event
  
  // 分页查询食物数据
  const result = await db.collection('foods')
    .where({ type })
    .skip((page - 1) * pageSize)
    .limit(pageSize)
    .get()

  return {
    code: 200,
    data: result.data,
    message: 'success'
  }
}